package main

import (
	"fmt"
	"net"
	"net/rpc"
	"net/rpc/jsonrpc"
)

func main() {
	// 1.用rpc.Dial和rpc微服务端建立连接
	// conn, err := rpc.Dial("tcp", "127.0.0.1:9000")
	conn, err := net.Dial("tcp", "127.0.0.1:9000")
	if err != nil {
		fmt.Println(err)
		return
	}

	// 2.客户端退出关闭连接
	defer conn.Close()

	client := rpc.NewClientWithCodec(jsonrpc.NewClientCodec(conn))

	// 3.调用远程函数
	// json rpc [" method ":" hello. SayHello ", "params" : ["zhang"], "id" : 0}
	var reply string
	err = client.Call("hello.SayHello", "你好", &reply)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(reply)

}
